package com.nerve.cloudoffice.web.action;

import com.nerve.cloudoffice.common.Reply;
import com.nerve.cloudoffice.common.util.JSONHelper;
import com.nerve.cloudoffice.domain.Notify;
import com.nerve.cloudoffice.service.NotifyService;
import com.nerve.cloudoffice.service.impl.NotifyServiceImpl;
import com.nerve.cloudoffice.web.model.NotifyModel;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @project cloudOffice NotifyAction.java
 * @datetime Aug 2, 2013 3:39:54 AM
 * @description 
 *    
 * @author 集成显卡 IBM 
 *			zxingming@qq.com
 *			zengxm@cn.ibm.com
 *
 * @change log:
 *
 */
@SuppressWarnings("serial")
public class NotifyAction extends NerveAction implements ModelDriven<NotifyModel>{
	
	private NotifyService service = new NotifyServiceImpl();
	
	private NotifyModel model = new NotifyModel();
	
	/**
	 * 发布一个通知
	 */
	public void add(){
		Reply re = new Reply();
		try{
			service.save(model);
			re.setMessage(model.getNotify().getId());
		}catch(Exception e){
			e.printStackTrace();
			re.setError(true);
			re.setMessage(e);
		}
		
		json(re);
	}
	
	public void delete(){
		Reply re = new Reply();
		try{
			service.delete(model);
			re.setMessage(SUCCESS);
		}catch(Exception e){
			e.printStackTrace();
			re.setError(true);
			re.setMessage(e.getMessage());
		}
		
		json(re);
	}

	/**
	 * 获取通知公告
	 */
	public void list(){
		Reply re = new Reply();
		try{
			service.list(model);
			re.setMessage(model.getNotifyList());
			re.setData(model.getTotalCount());
		}catch(Exception e){
			re.setError(true);
			re.setMessage(e.getMessage());
		}
		
		json(re, JSONHelper.getValueFilter(Notify.class));
	}

	public NotifyModel getModel() {
		return model;
	}

	public void setModel(NotifyModel model) {
		this.model = model;
	}
	
}